package com.example.visit

import com.blankj.utilcode.util.SPUtils
import com.example.base.mvi.BaseViewModel
import com.example.base.mvi.HttpType
import com.example.base.net.ApiService
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class VisitViewModel @Inject constructor(val apiService: ApiService): BaseViewModel<VisitIntent>(){
    override fun handleIntent(it: VisitIntent) {
        when(it){
            is VisitIntent.visit->httpRequest(apiService.visit())
            is VisitIntent.visitAdd->{
                httpRequest(apiService.visitAdd(toBody(it.item)))
            }
            is VisitIntent.upload->{
                httpRequest(apiService.upload(toPart(it.path,it.filename),"visit",SPUtils.getInstance().getInt("uid").toString()),HttpType.UPLOAD)
            }

            is VisitIntent.visitStatus -> {
            httpRequest(apiService.visitStatus(it.status))
            }

            is VisitIntent.visitName -> httpRequest(apiService.visitName(it.name))
            is VisitIntent.visitPurpose -> httpRequest(apiService.visitPurpose(it.purpose))
        }
    }
}